package com.shanghaionstar.test.api;


import android.os.Build;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.onstar.cn.auth.userProfile.request.UserProfileRequest;
import com.onstar.cn.common.BuildConfig;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.common.util.DeviceUtil;
import com.onstar.cn.framework.network.ClientTraceInstance;
import com.onstar.cn.mag.enumtype.OSType;
import com.shanghaionstar.OnstarApplication;
import com.shanghaionstar.retrofit.Api.HttpManagerApi;
import com.shanghaionstar.retrofit.listener.HttpOnNextListener;
import com.shanghaionstar.retrofit.listener.HttpOnNextSubListener;
import com.shanghaionstar.test.service.UsersService;
import com.shanghaionstar.utils.ApplicationUtil;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import java.util.HashMap;
import java.util.Map;


/**
 * 多api共存方案
 * Created by WZG on 2017/4/13.
 */

public class LoginApi extends HttpManagerApi {

    public LoginApi(HttpOnNextListener onNextListener, RxAppCompatActivity appCompatActivity) {
        super(onNextListener, appCompatActivity);
        /*统一设置*/
        setCache(true);
    }

    public LoginApi(HttpOnNextSubListener onNextSubListener, RxAppCompatActivity appCompatActivity) {
        super(onNextSubListener, appCompatActivity);
        /*统一设置*/
        setCache(true);
    }


    public void getUserProfile(){
        UserProfileRequest request = new UserProfileRequest();
        DeviceUtil deviceUtil = new DeviceUtil(OnstarApplication.getApplication());
        request.setOsType(OSType.ANDROID.value());
        request.setVersionCode(deviceUtil.getAppVersionCode() + "");
        request.setOSVersion(DeviceUtil.getOSVersion());
        UsersService service = getRetrofit().create(UsersService.class);
//        String requestJson = GsonHelper.toJson(request);
        doHttpDeal(service.getUserProfile(getHeaders(),request));
    }



//    public Subscriber getUserProfile() throws OnStarException {
//        boolean isSuccess = true;
//        long startTimeStamp = System.currentTimeMillis();
//        UsersService service = new UsersService(Constants.CURRENT_SERVER_URL);
//        RequestEntity requestEntity = NetConnectUtil.getAuthRequestEntity(context);
//        UserProfileRequest request = new UserProfileRequest();
//        DeviceUtil deviceUtil = new DeviceUtil(context);
//        request.setOsType(OSType.ANDROID.value());
//        request.setVersionCode(deviceUtil.getAppVersionCode() + "");
//        request.setOSVersion(DeviceUtil.getOSVersion());
//
//        requestEntity = service.getUserInfo3Profile(requestEntity, GsonHelper.toJson(request));//getUserProfile
//        requestEntity = HttpInjectUtils.injectHttp(getClass(), "getUserProfile", requestEntity);
//        Subscriber subscriber=null;
//        try{
//            String response = NetConnectUtil.getResponse(getDatas(requestEntity));
//            PreferencesUtls.getInstance(context).putString(Constants.AUTH_USER_PROFILE, response);
//            PreferencesUtls.getInstance(context).putLong(Constants.AUTH_USER_PROFILE_TIME, System.currentTimeMillis());
//            subscriber = GsonHelper.fromJson(response, Subscriber.class);
//        }catch (OnStarException e) {
//            isSuccess = false;
//            throw e;
//        }finally {
//            long endTimeStamp = System.currentTimeMillis();
//            ReportReqParam reportReqParam = ReportReqParam.getLoginReqParm(isSuccess);
//            reportReqParam.startTimestamp = startTimeStamp;
//            reportReqParam.endTimestamp = endTimeStamp;
//            reportReqParam.functionNameFindId = FunctionNameFindId.ManualLogin_GetProfile.getStringValue();
//            BusinessUtil.sendReportByRequestParams(context, FunctionNameFindId.ManualLogin_GetProfile.getStringValue(),reportReqParam);
//        }
//
//        handleSubscriber(subscriber);
//        return subscriber;
//    }
//




}
